package org.example.userservice.parsetoken;

import io.jsonwebtoken.Claims;
import jakarta.servlet.http.HttpServletRequest;
import org.example.userservice.untils.JWTUntils;

//！！！！此为AI生成
public class ParseToken {
    // 获取用户ID
    public static Long getUserIdFromToken(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        Claims claims = JWTUntils.getClaims(token);
        return Long.valueOf(claims.getSubject());
    }
    //获取用户权限码
    public static String getRoleCodeFromToken(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        Claims claims = JWTUntils.getClaims(token);
        return claims.get("userRole", String.class);
    }
}
